//Creates/Saves/Loads games

package game.system;

import java.io.*;
import java.util.*;

import game.info.Player;
import game.tools.Sleep;

public class GameData {

	public void create(Player p) throws Exception { //Creates a new TXT files with the default attributes of the player object
		
		String output = "";
		Scanner contentReader = new Scanner (new File("src/content.txt")); 
		
		for (int i = 0 ; i < 50; i++) {
			
			output = contentReader.nextLine();
			System.out.println(output);
			
		}
		
		Scanner input = new Scanner (System.in);
			
		System.out.print("	Enter your name: ");
		String name = input.nextLine();
		p.setPlayerName(name);
			
		String playerName = p.getPlayerName();
		String petName = p.getPetName();
		int playerLocation = p.getPlayerLocation();
		int playerVerdict = p.getPlayerVerdict();
		boolean hasPet = p.getHasPet();
		boolean hasPliers = p.getHasPliers();
		boolean hasPaperclip = p.getHasPaperclip();
		boolean hasBentPaperclip = p.getHasBentPaperclip();
		boolean hasOpenedDesk = p.getHasOpenedDesk();
		boolean hasWrench = p.getHasWrench();
		boolean hasKey = p.getHasKey();
		boolean hasSpoon = p.getHasSpoon();
		boolean hasKnife = p.getHasKnife();;
		boolean hasGun = p.getHasGun();
		boolean hasOpenedDrawer = p.getHasOpenedDrawer();
		boolean hasUnboltedSafe = p.getHasUnboltedSafe();
		boolean hasGuiltyCombination = p.getHasGuiltyCombination();
		boolean hasInnocentCombination = p.getHasInnocentCombination();
		boolean hasCandlelabra = p.getHasCandlelabra();
		boolean hasLitCandlelabra = p.getHasLitCandlelabra();
		boolean hasCauldron = p.getHasCauldron();
		boolean hasEmptiedCauldron = p.getHasEmptiedCauldron();
		boolean hasButterknife = p.getHasButterknife();
		boolean hasWine = p.getHasWine();
		boolean hasEmptiedWine = p.getHasEmptiedWine();
		boolean hasBottleneckKnife = p.getHasBottleneckKnife();
		boolean hasNapkins = p.getHasNapkins();
		boolean hasLemons = p.getHasLemons();
		boolean hasAcidBattery = p.getHasAcidBattery();
		boolean hasDrenchedRug = p.getHasDrenchedRug();
		boolean hasOpenedCabinets = p.getHasOpenedCabinets();
			
		File file = new File(playerName + ".txt");
		
		if (file.exists()) {
				
			System.out.println("	This name is already in use! Please enter a different name.");
				
		} else {
			
			System.out.println("	Profile being created... Creating game...");
			PrintWriter out = new PrintWriter(new FileWriter(file));
					
			out.println(playerName);
			out.println(petName);
			out.println(hasPet);
			out.println(hasPliers);
			out.println(hasPaperclip);
			out.println(hasBentPaperclip);
			out.println(hasOpenedDesk);
			out.println(hasWrench);
			out.println(hasKey);
			out.println(hasSpoon);
			out.println(hasKnife);
			out.println(hasGun);
			out.println(hasOpenedDrawer);
			out.println(hasUnboltedSafe);
			out.println(hasGuiltyCombination);
			out.println(hasInnocentCombination);
			out.println(hasCandlelabra);
			out.println(hasLitCandlelabra);
			out.println(hasCauldron);
			out.println(hasEmptiedCauldron);
			out.println(hasButterknife);
			out.println(hasWine);
			out.println(hasEmptiedWine);
			out.println(hasNapkins);
			out.println(hasLemons);
			out.println(hasAcidBattery);
			out.println(hasDrenchedRug);
			out.println(hasOpenedCabinets);
			out.close();
				
		}
			
			
	}
		
	public void save(Player p) throws Exception { //Updates the player's TXT file to the current attributes of the player object
   
		String playerName = p.getPlayerName();
		String petName = p.getPetName();
		int playerLocation = p.getPlayerLocation();
		int playerVerdict = p.getPlayerVerdict();
		boolean hasPet = p.getHasPet();
		boolean hasPliers = p.getHasPliers();
		boolean hasPaperclip = p.getHasPaperclip();
		boolean hasBentPaperclip = p.getHasBentPaperclip();
		boolean hasOpenedDesk = p.getHasOpenedDesk();
		boolean hasWrench = p.getHasWrench();
		boolean hasKey = p.getHasKey();
		boolean hasSpoon = p.getHasSpoon();
		boolean hasKnife = p.getHasKnife();;
		boolean hasGun = p.getHasGun();
		boolean hasOpenedDrawer = p.getHasOpenedDrawer();
		boolean hasUnboltedSafe = p.getHasUnboltedSafe();
		boolean hasGuiltyCombination = p.getHasGuiltyCombination();
		boolean hasInnocentCombination = p.getHasInnocentCombination();
		boolean hasCandlelabra = p.getHasCandlelabra();
		boolean hasLitCandlelabra = p.getHasLitCandlelabra();
		boolean hasCauldron = p.getHasCauldron();
		boolean hasEmptiedCauldron = p.getHasEmptiedCauldron();
		boolean hasButterknife = p.getHasButterknife();
		boolean hasWine = p.getHasWine();
		boolean hasEmptiedWine = p.getHasEmptiedWine();
		boolean hasBottleneckKnife = p.getHasBottleneckKnife();
		boolean hasNapkins = p.getHasNapkins();
		boolean hasLemons = p.getHasLemons();
		boolean hasAcidBattery = p.getHasAcidBattery();
		boolean hasDrenchedRug = p.getHasDrenchedRug();
		boolean hasOpenedCabinets = p.getHasOpenedCabinets();
   
		File file = new File(playerName + ".txt");
		
		if (file.exists()) {
      
			PrintWriter out = new PrintWriter(new FileWriter(file));
					
			out.println(playerName);
			out.println(petName);
			out.println(hasPet);
			out.println(hasPliers);
			out.println(hasPaperclip);
			out.println(hasBentPaperclip);
			out.println(hasOpenedDesk);
			out.println(hasWrench);
			out.println(hasKey);
			out.println(hasSpoon);
			out.println(hasKnife);
			out.println(hasGun);
			out.println(hasOpenedDrawer);
			out.println(hasUnboltedSafe);
			out.println(hasGuiltyCombination);
			out.println(hasInnocentCombination);
			out.println(hasCandlelabra);
			out.println(hasLitCandlelabra);
			out.println(hasCauldron);
			out.println(hasEmptiedCauldron);
			out.println(hasButterknife);
			out.println(hasWine);
			out.println(hasEmptiedWine);
			out.println(hasNapkins);
			out.println(hasLemons);
			out.println(hasAcidBattery);
			out.println(hasDrenchedRug);
			out.println(hasOpenedCabinets);
			out.close();
    
		}
			
	}
		
	public String[][][][] load(Player p) throws Exception { //Reads and sets the player attributes to the previously saved player object
		
		long l = 3000;
		Sleep s = new Sleep();
		String[][][][] rooms = {{{{}}}};
		
		Scanner input = new Scanner(System.in);
		System.out.println("	Enter the name of the character you wish to load: ");
		String playerName = input.nextLine();
		File file = new File(playerName + ".txt");
		
		if (file.exists()) {
			
			
			System.out.println("	File found! Loading game...");
			
			Scanner contentReader = new Scanner (new File(playerName + ".txt"));
			playerName = contentReader.nextLine();
			String petName = contentReader.nextLine();
			int playerLocation = Integer.parseInt(contentReader.nextLine());
			int playerVerdict = Integer.parseInt(contentReader.nextLine());
			boolean hasPet = Boolean.parseBoolean(contentReader.nextLine()); 
			boolean hasPliers = Boolean.parseBoolean(contentReader.nextLine());
			boolean hasPaperclip = Boolean.parseBoolean(contentReader.nextLine());
			boolean hasBentPaperclip = Boolean.parseBoolean(contentReader.nextLine());
			boolean hasOpenedDesk = Boolean.parseBoolean(contentReader.nextLine());
			boolean hasWrench = Boolean.parseBoolean(contentReader.nextLine());
			boolean hasKey = Boolean.parseBoolean(contentReader.nextLine());
			boolean hasSpoon = Boolean.parseBoolean(contentReader.nextLine());
			boolean hasKnife = Boolean.parseBoolean(contentReader.nextLine());
			boolean hasGun = Boolean.parseBoolean(contentReader.nextLine());
			boolean hasOpenedDrawer = Boolean.parseBoolean(contentReader.nextLine());
			boolean hasUnboltedSafe = Boolean.parseBoolean(contentReader.nextLine());
			boolean hasGuiltyCombination = Boolean.parseBoolean(contentReader.nextLine());;
			boolean hasInnocentCombination = Boolean.parseBoolean(contentReader.nextLine());
			boolean hasCandlelabra = Boolean.parseBoolean(contentReader.nextLine());
			boolean hasLitCandlelabra = Boolean.parseBoolean(contentReader.nextLine());
			boolean hasCauldron = Boolean.parseBoolean(contentReader.nextLine());
			boolean hasEmptiedCauldron = Boolean.parseBoolean(contentReader.nextLine());
			boolean hasButterknife = Boolean.parseBoolean(contentReader.nextLine());
			boolean hasWine = Boolean.parseBoolean(contentReader.nextLine());
			boolean hasEmptiedWine = Boolean.parseBoolean(contentReader.nextLine());
			boolean hasBottleneckKnife = Boolean.parseBoolean(contentReader.nextLine());
			boolean hasNapkins = Boolean.parseBoolean(contentReader.nextLine());
			boolean hasLemons = Boolean.parseBoolean(contentReader.nextLine());
			boolean hasAcidBattery = Boolean.parseBoolean(contentReader.nextLine());
			boolean hasDrenchedRug = Boolean.parseBoolean(contentReader.nextLine());
			boolean hasOpenedCabinets = Boolean.parseBoolean(contentReader.nextLine());
			
			
			Player.setPlayerName(playerName);
			Player.setPlayerLocation(playerLocation);
			Player.setPlayerVerdict(playerVerdict);
			Player.setPetName(petName);
			Player.setHasPet(hasPet);
			Player.setHasPliers(hasPliers);
			Player.setHasPaperclip(hasPaperclip);
			Player.setHasBentPaperclip(hasBentPaperclip);
			Player.setHasOpenedDesk(hasOpenedDesk);
			Player.setHasWrench(hasWrench);
			Player.setHasKey(hasKey);
			Player.setHasSpoon(hasSpoon);
			Player.setHasKnife(hasKnife);
			Player.setHasGun(hasGun);
			Player.setHasOpenedDrawer(hasOpenedDrawer);
			Player.setHasUnboltedSafe(hasUnboltedSafe);
			Player.setHasGuiltyCombination(hasGuiltyCombination);
			Player.setHasInnocentCombination(hasInnocentCombination);
			Player.setHasCandlelabra(hasCandlelabra);
			Player.setHasLitCandlelabra(hasLitCandlelabra);
			Player.setHasCauldron(hasCauldron);
			Player.setHasEmptiedCauldron(hasEmptiedCauldron);
			Player.setHasButterknife(hasButterknife);
			Player.setHasWine(hasWine);
			Player.setHasEmptiedWine(hasEmptiedWine);
			Player.setHasBottleneckKnife(hasBottleneckKnife);
			Player.setHasNapkins(hasNapkins);
			Player.setHasLemons(hasLemons);
			Player.setHasAcidBattery(hasAcidBattery);
			Player.setHasDrenchedRug(hasDrenchedRug);
			Player.setHasOpenedCabinets(hasOpenedCabinets);
			
			System.out.println("	Welcome back " + playerName);
				
		}
		return rooms;
		
		
	}
	
}
	

	
